<?php 
namespace Modules\ShopAdmin\Http\Controllers\v1;
use Illuminate\Http\Request;
use Modules\AuthAdmin\Services\CommonService;
use Modules\AuthAdmin\Http\Requests\CommonIdRequest;
use Modules\AuthAdmin\Http\Requests\CommonStatusRequest;
use Modules\AuthAdmin\Http\Requests\CommonSortRequest;
use Modules\ShopAdmin\Models\ShopConsult as ShopConsultModel;
use Modules\ShopAdmin\Models\ShopConsultEvaluate as ShopConsultEvaluateModel;
class ConsultController extends CommonController
{
	/**
	 * @name  咨询列表
	 * @method  GET	
	 * @param  page int 页码
	 * @param  pagesize int 每页条数	
	 * @param  key string 咨询标题		
	 * @param  status int 状态:0=禁用,1=启用	
	 * @param  created_at string 创建时间	
	 * @param  updated_at string 更新时间	
	 * @return  JSON
	 */
    public function index(Request $request)
    {
		return (new ShopConsultModel())->list_data($request->all());
    }
	/**
	 * @name  添加
	 * @method  POST	
	 * @param  title string 咨询标题	
	 * @param  author string 作者	
	 * @param  images string 图片多个用|线隔开	
	 * @param  reading_quantity int 阅读量	
	 * @param  like_number int 点赞数	
	 * @param  content string 详情
	 * @param  sort int 排序	
	 * @return  JSON
	 */
    public function store(Request $request)
    {
		$data = $request->all();
		$data['content'] = (new CommonService())->remve_pic_url($data['content']);
		return (new ShopConsultModel())->common_create($data);
    }
	/**
	 * @name  编辑页面
	 * @method  GET	
	 * @param  id int 咨询ID	
	 * @return  JSON
	 */
    public function edit(CommonIdRequest $request)
    {
		return (new ShopConsultModel())->get_edit($request->get('id'));
    }
	/**
	 * @name  编辑提交
	 * @method  PUT	
	 * @param  id int 咨询ID
	 * @param  title string 咨询标题	
	 * @param  author string 作者	
	 * @param  images string 图片多个用|线隔开	
	 * @param  reading_quantity int 阅读量	
	 * @param  like_number int 点赞数
	 * @param  content string 详情
	 * @param  sort int 排序	
	 * @return  JSON
	 */ 
    public function update(Request $request)
    {
		$data = $request->all();
		return (new ShopConsultModel())->common_update($data['id'],[
			'title'=>$data['title'],
			'author'=>$data['author'],
			'images'=>$data['images'],
			'reading_quantity'=>$data['reading_quantity'],
			'like_number'=>$data['like_number'],
			'content'=>(new CommonService())->remve_pic_url($data['content']),
			'sort'=>$data['sort'],
		]); 
    }
	/**
	 * @name  调整状态
	 * @method  PUT	
	 * @param  id int 咨询ID
	 * @param  status int 状态（0或1）
	 * @return  JSON
	 */ 
    public function status(CommonStatusRequest $request)
    {
		$data = $request->all();
		return (new ShopConsultModel())->common_status_update($data['id'],['status'=>$data['status']]); 
    }
	/**
	 * @name  排序
	 * @method  PUT	
	 * @param  id int 咨询ID
	 * @param  sort int 排序
	 * @return  JSON
	 */ 
    public function sorts(CommonSortRequest $request)
    {
		$data = $request->all();
		return (new ShopConsultModel())->common_sort_update($data['id'],['sort'=>$data['sort']]); 
    }
	
	/**
	 * @name  删除
	 * @method  DELETE	
	 * @param  id int 咨询ID
	 * @return  JSON
	 */
    public function destroy(CommonIdRequest $request)
    {
		return (new ShopConsultModel())->common_destroy($request->get('id'));
    }
	
	/**
	 * @name  咨询评价列表
	 * @method  GET	
	 * @return  JSON
	 */
    public function evaluate_index(CommonIdRequest $request)
    {
		return (new ShopConsultEvaluateModel())->list_data($request->get('id'));
    }
	/**
	 * @name  咨询评价状态
	 * @method  PUT	
	 * @param  id int 咨询评价ID
	 * @param  status int 状态（0或1）
	 * @return  JSON
	 */ 
    public function evaluate_status(CommonStatusRequest $request)
    {
		$data = $request->all();
		return (new ShopConsultEvaluateModel())->common_status_update($data['id'],['status'=>$data['status']]); 
    }
	/**
	 * @name  咨询评价删除
	 * @method  DELETE	
	 * @param  id int 咨询评价ID
	 * @return  JSON
	 */
    public function evaluate_destroy(CommonIdRequest $request)
    {
		$id = $request->get('id');
		$arr = ShopConsultEvaluateModel::where(['pid'=>$id])->pluck('id');
		$arr[] = $id;
		return (new ShopConsultEvaluateModel())->common_destroy($arr);
    }
	
	
}
